const express = require("express");
const router = express.Router();

const MySql = require("./../lib/mysql");

router.post("/userLogin",async(req,res,next) => {

    //从前端得到的表单内容传到后台
    const id = req.body.id;
    const password = req.body.password;

    

//     //数据库操作
    const res1 = await MySql.query('select * from user where id=?',[id]);
    if(res1.length == 0){
        res.json({
            code:0,
            message:'用户名不存在'
        })
        return;
    }
    const user = res1[0];
    if(user.password == password){
        res.json({
            code:1,
            message:'登录成功',
        })
    }
    else{
        res.json({
            code: 0,
            message: "登录失败",
          });
    }
   


});

module.exports = router;